<template>
	<view class="ALL">
		<image :src="bg" mode=""></image>
		<view class="box">
			<view class="top">
				<text>请登录</text>
			</view>
			<view class="mid">
				<view class="mid-userid">
					<input type="text" value="" placeholder="请输入用户名/账号" @input="userId" />
				</view>
				<view class="mid-password">
					<input type="text" value="" :password="showPassword" placeholder="请输入密码" @input="userPassword" />
					<image :src="closepasw" mode="" @click="showPwd"></image>
					<image :src="seepasw" mode="" @click="showPwd"></image>
				</view>
				<view class="ensure" @tap="Login">
					<text>登录</text>
				</view>
			</view>
			<view class="bottom">
				<text class="forger" @tap="forget">忘记密码？</text>
				<text class="register" @tap="register">立即注册</text>
			</view>
		</view>
	</view>
</template>

<script>
	import apis from '../../api.js'
	import icons from "../../common/icons.js"
	import {
		mapState,
		mapMutations
	} from "vuex";
	export default {
		data() {
			return {
				showPassword: true,
				loginform: {
					user: '',
					password: '',
				},
				token: '',
				closepasw:icons.icons.closepasw,
				seepasw:icons.icons.seepasw,
				bg:icons.icons.bg,
			}
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onLoad() {
			uni.login({
				provider: 'weixin',
				success: function(loginRes) {
					console.log(loginRes);
					// 获取用户信息
					uni.getUserInfo({
						provider: 'weixin',
						success: function(infoRes) {
							console.log('用户昵称为：' + infoRes.userInfo.nickName);
						}
					});
				}
			});
		},
		methods: {
			...mapMutations(['login']),
			showPwd: function() {
				this.showPassword = !this.showPassword;
			},
			userId(e) {
				console.log(e.detail.value)
				this.loginform.user = e.detail.value

			},
			userPassword(e) {
				console.log(e.detail.value)
				this.loginform.password = e.detail.value

			},
			register() {
				uni.navigateTo({
					url: '../register/register'
				})
			},
			Login() {
				var that = this
				console.log(this.loginform)
				apis.login({
					user: this.loginform.user,
					password: this.loginform.password
				}).then(res => {
					console.log(res)
					if(res[1].data.code==200){
						that.token = res[1].data.token
						uni.showToast({
							title: res[1].data.msg,
							icon: 'none'
						}),
						uni.setStorage({
							key: 'token',
							data: that.token,
							success: function() {
								console.log('success');
								uni.reLaunch({
									url:'../fastappointment/fastappointment'
								})
							}
						});
					}else{
						uni.showToast({
							title: res[1].data.msg,
							icon: 'none'
						})
					}
					
				})
			},
			forget() {
				uni.navigateTo({
					url: '../forgetpassword/forgetpassword'
				})
			}
		}
	}
</script>

<style scoped>
	.ALL {
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.ALL>image {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		z-index: -1;
	}

	.box {
		width: 686rpx;
		height: 622rpx;
		margin-top: 320rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		display: flex;
		flex-direction: column;
		/* justify-content: center; */
		align-items: center;
	}

	.top {
		width: 100%;
		margin-top: 60rpx;
		text-align: center;
	}

	.top>text {
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 1000;
		color: #212121;
	}

	.mid-userid {
		width: 624rpx;
		height: 130rpx;
		display: flex;
		align-items: center;
		border-bottom: 2rpx solid #E6E9EE;
	}

	.mid-userid>input {
		margin-top: 40rpx;
	}

	.mid-password {
		width: 624rpx;
		height: 130rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 2rpx solid #E6E9EE;
	}

	.mid-password>image {
		width: 36rpx;
		height: 28rpx;
		margin-top: 40rpx;
	}

	.mid-password>input {
		width: 80%;
		margin-top: 40rpx;
	}

	.ensure {
		width: 624rpx;
		height: 88rpx;
		background: #000000;
		border-radius: 12rpx;
		color: #B6914E;
		text-align: center;
		line-height: 88rpx;
		font-size: 36rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 1000;
		margin-top: 60rpx;
	}

	.bottom {
		width: 624rpx;
		margin-top: 37rpx;
		display: flex;
		justify-content: space-between;
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 800;
		color: #333333;
	}
</style>
